#include "configurationdialog.h"
#include "ui_configurationdialog.h"
#include <QtCore>
#include <QPushButton>

ConfigurationDialog::ConfigurationDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ConfigurationDialog)
{
    ui->setupUi(this);
    connect(ui->Player1Line,&QLineEdit::textChanged,this,&ConfigurationDialog::UpdateOKButtonState);
    connect(ui->Player2Line,&QLineEdit::textChanged,this,&ConfigurationDialog::UpdateOKButtonState);
    UpdateOKButtonState();
}

ConfigurationDialog::~ConfigurationDialog()
{
    delete ui;
}

void ConfigurationDialog::SetPlayer1Name(const QString& p_name)
{
    ui->Player1Line->setText(p_name);
}

void ConfigurationDialog::SetPlayer2Name(const QString &p_name)
{
    ui->Player2Line->setText(p_name);
}

QString ConfigurationDialog::Player1Name() const
{
    return ui->Player1Line->text();
}

QString ConfigurationDialog::Player2Name() const
{
    return ui->Player2Line->text();
}

void ConfigurationDialog::UpdateOKButtonState()
{
    QPushButton* button = ui->buttonBox->button(ui->buttonBox->Ok);
    button->setEnabled(!ui->Player1Line->text().isEmpty() && !ui->Player2Line->text().isEmpty());
}
